<?php


namespace App\Service;


use App\Models\Advert\Advert;
use App\Models\Constant\UploadConstant;
use App\Models\School\School;
use App\Models\Student\Ask;

class IndexService extends CommonService {

    public function getBanner(int $type,int $limit=5) {
        return Advert::where(['type'=>$type,'status'=>1])->where(function ($q){
            $q->where('auto_disable_time',">=",date('Y-m-d H:i:s'))
                ->orWhere('auto_disable_time','=',null);
        })->orderByDesc('sort')->orderBy('is_top')->orderByDesc('id')->limit($limit)->get();
    }

    public function getCollegeBanner($collegePage) {
        /*$map = UploadConstant::MAP_ADVERT_TYPE;
        $collegeTypes = Advert::whereIn('type',range(5, count($map)-1))
            ->orderByDesc('sort')->orderBy('is_top')->orderByDesc('id')->forPage($collegePage,6)->get(['type']);
        $colleges = [];
        foreach ($collegeTypes as $collegeType) {
            $colleges[] = Advert::where('type',$collegeType->type)->orderByDesc('sort')->orderBy('is_top')->orderByDesc('id')
                ->first()->toArray();
        }*/

        $colleges = School::where('status',1)->get();



        return $colleges;

    }

    public function ask($name,$phone,$wx) {
        return Ask::updateOrCreate(compact('phone'),compact('phone','name','wx'));
    }

    public function getSchoolWithTemplateContent(){
        return School::where('status',1)->whereNotNull('template_content')->get(['id','name','pic_url']);
    }


}
